home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
os2
/
mbase101.zip
/
plugins.Zip
/
printrec.nrx
< prev
next >
Wrap
Text File
|
1997-04-15
|
5KB
|
193 lines
/*
PrintRec, a NetRexx app to create text documents
from selected records for printing
*/
class printrec extends Frame
properties public
rx = RXFile()
rxPrint = RXFile()
rHowManyFld = Rexx
rHowManyRec = Rexx
rFieldName = Rexx[]
rFieldValue = Rexx[,]
iCount = int
iCount2 = int
iMaxLength = 0
bPrintHeader = boolean 1
bPrintFieldNames = boolean 1
bActuallyPrint = boolean 1
rPrintCommand = Rexx "cmd.exe /c copy printme.txt lpt1:"
rHeader1 = Rexx "MaxBase 1.0, Copyright 1997 Max Marsiglietti -- record dump"
rHeader2 = Rexx "------- ---- --------- ---- --- ------------ -- ------ ----"
rtime = Runtime
pr2 = Process
pCenter = Panel -- Here we'll lay all the other textfields/areas, labels.
cbActuallyPrint = CheckBox("Actually Print")
cbPrintHeader = CheckBox("Print Header")
cbPrintFieldNames = CheckBox("Also print FieldNames")
laHeader1 = Label("Header Line 1:")
laHeader2 = Label("Header Line 2:")
tfHeader1 = TextField(rHeader1)
tfHeader2 = TextField(rHeader2)
laPrintCommand = Label("PrintCommand:")
tfPrintCommand = TextField(rPrintCommand)
bPrintIt = Button("Create printme.txt file")
method main(s=String[]) static
s=s
printrec()
method printrec
super("Record Printing: 1 record")
super.setResizable(1)
rHowManyFld = rx.linein() /* How many fields? */
rFieldName = Rexx[rHowManyFld + 1]
loop iCount = 1 to rHowManyFld
rFieldName[iCount] = rx.linein() /* Get field names */
if rFieldName[iCount].length > iMaxLength then
iMaxLength = rFieldName[iCount].length
end
rHowManyRec = rx.linein() /* How many records? */
rFieldValue = Rexx[rHowManyFld + 1, rHowManyRec + 1]
loop iCount = 1 to rHowManyRec /* Records */
loop iCount2 = 1 to rHowManyFld
rFieldValue[iCount2, iCount] = rx.linein()
end
end
/*
Now we have:
in rFieldName[1..rHowManyFld] all the field names.
in rFieldValue[1..rHowManyFld, 1..rHowManyRec] all the records that the user
has selected before calling the plugin, field by field and record by record.
*/
loop iCount = 1 to rHowManyFld
rFieldName[iCount] = rFieldName[iCount].left(iMaxLength)
end
setupFrame
method setupFrame
pOne = Panel()
pTwo = Panel()
pThree = Panel()
pFour = Panel()
tfPrintCommand.setBackGround(Color(255, 255, 204))
tfHeader1.setBackGround(Color(255, 255, 204))
tfHeader2.setBackGround(Color(255, 255, 204))
cbActuallyPrint.setState(bActuallyPrint)
cbPrintHeader.setState(bPrintHeader)
cbPrintFieldNames.setState(bPrintFieldNames)
pCenter = Panel()
pCenter.setLayout(GridLayout(4, 1))
pCenter.removeAll
pOne.setLayout(FlowLayout(FlowLayout.LEFT))
pOne.add(laHeader1)
pOne.add(tfHeader1)
pCenter.add(pOne)
pTwo.setLayout(FlowLayout(FlowLayout.LEFT))
pTwo.add(laHeader2)
pTwo.add(tfHeader2)
pCenter.add(pTwo)
pThree.setLayout(FlowLayout(FlowLayout.LEFT))
pThree.add(laPrintCommand)
pThree.add(tfPrintCommand)
pCenter.add(pThree)
pFour.setLayout(FlowLayout(FlowLayout.LEFT))
pFour.add(cbActuallyPrint)
pFour.add(cbPrintHeader)
pFour.add(cbPrintFieldNames)
pCenter.add(pFour)
this.add("Center", pCenter)
this.add("South", bPrintIt)
this.reshape(Toolkit.getDefaultToolkit.getScreenSize.width % 2 - 320, Toolkit.getDefaultToolkit.getScreenSize.height %2 - 100, 640, 200)
if rHowManyRec > 1 then
this.setTitle("Record printing: "rHowManyRec" records")
this.show()
method handleEvent(e=Event) returns boolean
if e.target = bPrintIt then PrintIt
if e.id=Event.WINDOW_DESTROY then
exit
return super.handleEvent(e)
method Printit
bActuallyPrint = cbActuallyPrint.getState()
bPrintHeader = cbPrintHeader.getState()
bPrintFieldNames = cbPrintFieldNames.getState()
rHeader1 = tfHeader1.getText()
rHeader2 = tfHeader2.getText()
rPrintCommand = tfPrintCommand.getText()
-- If the file already exists, delete it
if rxPrint.stream("printme.txt", "c", "query exists") \= "" then
rxPrint.delete("printme.txt")
-- Create the file
rxPrint.stream("printme.txt", "c", "open write")
-- create the header
if bPrintHeader = 1 then
do
rxPrint.lineout(rHeader1)
rxPrint.lineout(rHeader2)
rxPrint.lineout(" ")
end
-- now the records (in form view)
loop iCount = 1 to rHowManyRec
loop iCount2 = 1 to rHowManyFld
if bPrintFieldNames = 1 then
rxPrint.lineout(rFieldName[iCount2] || " : " || rFieldValue[iCount2, iCount].strip())
else
rxPrint.lineout(rFieldValue[iCount2, iCount].strip())
end
rxPrint.lineout("--")
rxPrint.lineout(" ")
end
-- Close the stream
rxPrint.stream("printme.txt", "c", "close")
if bActuallyPrint = 1 then
do
/* fire up the printing command */
rtime = Runtime.getRuntime()
do
pr2 = rtime.exec(rPrintCommand)
pr2.waitfor()
catch IOException
catch InterruptedException
catch NullPointerException
exit
end
end